<template>
  <!-- 2023年4月3日 孔德嘉 DIY首页 -->
  <div style="background: #fff">
    <!-- 轮播图 -->
    <div class="block">
      <el-carousel height="528px">
        <el-carousel-item v-for="(item, index) in bannerUrl" :key="index">
          <el-image
            :src="`${$imageUrl}?id=` + item.imageId"
            @click.native="toOther(item)"
          ></el-image>
        </el-carousel-item>
      </el-carousel>
    </div>
    <!-- 中间内容 -->
    <div class="center"> 
      <!-- 今日特价 -->
      <NowDayCheap></NowDayCheap>
    </div>
    <!-- 图片 -->
    <div class="center_img">
      <el-image :src="centerImg1"></el-image>
      <el-image :src="centerImg1"></el-image>
    </div>
    <!-- 中间内容 -->
    <div class="center">
      <!-- 特色DIY -->
      <CharacteristicDIY></CharacteristicDIY>
      <!-- 分类 -->
      <div class="classify">
        <h1
          style="
            text-align: center;
            letter-spacing: 10px;
            font-family: 'Times New Roman', Times, serif;
            margin: 30px 0 40px 0;
            font-weight: 400;
          "
        >
          商品系列大赏
        </h1>
        <div class="classify_i">
          <el-row>
            <el-col
              :span="6"
              v-for="(item, index) in classifyList"
              :key="index"
              :offset="index % 3 != 0 ? 3 : 0"
              style="height: 400px"
            >
              <!-- 内容 -->
              <div class="card1">
                <div class="card-inner">
                  <div style="width: 100%; aspect-ratio: 1/1">
                    <el-image
                      :src="$imageUrl + '?id=' + item.imageId"
                      class="image"
                      @click="toDiyShopsByType(item.id)"
                    >
                      <div slot="placeholder">
                        <Loading></Loading>
                      </div>
                    </el-image>
                  </div>
                  <div style="padding: 14px">
                    <span style="font-size: 14px; font-weight: bold">{{
                      item.typeName
                    }}</span>
                    <div class="bottom clearfix">
                      <button class="btn" @click="toDiyShopsByType(item.id)">
                        立即查看
                        <svg
                          xmlns="http://www.w3.org/2000/svg"
                          fill="none"
                          viewBox="0 0 24 24"
                          height="15px"
                          width="15px"
                          class="icon"
                        >
                          <path
                            stroke-linejoin="round"
                            stroke-linecap="round"
                            stroke-miterlimit="10"
                            stroke-width="1.5"
                            stroke="#292D32"
                            d="M8.91016 19.9201L15.4302 13.4001C16.2002 12.6301 16.2002 11.3701 15.4302 10.6001L8.91016 4.08008"
                          ></path>
                        </svg>
                      </button>
                    </div>
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CharacteristicDIY from "@/components/diy/CharacteristicDIY.vue";
import NowDayCheap from "@/components/diy/NowDayCheap";
import Loading from "@/components/diy/Loading";
export default {
  name: "DIYIndex",
  data() {
    return {
      //分类
      classifyList: [],
      // 插图
      centerImg1: require("../../assets/image/banner1.png"),
      //banner 轮播图
      bannerUrl: [],
    };
  },
  mounted() {
    // 获取轮播图信息
    this.slideShowByType();
    //获取分类信息
    this.getHandworkDiyTypeList();
  },
  components: {
    CharacteristicDIY,
    NowDayCheap,
    Loading,
  },
  methods: {
    // 获取轮播图信息
    slideShowByType() {
      this.$axios
        .get("/slideShow/slideShowByTypeDiy")
        .then((res) => {
          if (res.data.flag) {
            // debugger;
            this.bannerUrl = res.data.data;
          } else {
            this.myMessage("error", res.data.data);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 跳转到DIY商品详情页面
    toDIYView(id) {
      this.$router.push({
        path: "/DIYView",
        query: { diyId: id },
      });
    },
    toDiyShopsByType(id) {
      //查看更多
      //前往商品页面
      this.$router.push({
        path: "/DIYShops",
        query: { typeId: id },
      });
    },
    toOther(data) {
      console.log(data);
      //查看更多
      //前往商品页面
      this.$router.push({
        path: data.url,
        query: { diyId: data.carouselId },
      });
    },
    // 查询DIY的类型列表
    getHandworkDiyTypeList() {
      this.$axios
        .get("/handworkDiy/getHandworkDiyTypeList")
        .then((res) => {
          // 查询DIY的类型列表
          this.classifyList = res.data.data;
        })
        .catch(() => {
          this.$message.error("获取DIY分类失败！");
        });
    },
  },
};
</script>

<style scoped>
/** 导航 */
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

/*页面居中*/
.center {
  width: 80%;
  margin: 0 auto;
}
/*中间图片*/
.center_img {
  width: 100%;
  height: 260px;
}
.center_img > div {
  width: 50%;
  display: inline-block;
}
.center_img img {
  height: 220px;
  display: inline-block;
}

/*分类*/
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.image {
  aspect-ratio: 1/1;
  width: 100%;
  display: block;
}
.classify {
  margin-top: 30px;
  padding-top: 20px;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
.classify_i {
  width: 60%;
  margin: 0 auto;
}
/*分类*/
.card1 {
  width: 100%;
  height: auto;
  transition: all 0.2s;
  position: relative;
  cursor: pointer;
}

.card-inner {
  width: inherit;
  height: inherit;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
  border-radius: 8px;
}

.card1:hover {
  transform: scale(1.04);
}
/*按钮*/
.btn {
  padding-left: 0px;
  width: 100px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  text-transform: uppercase;
  letter-spacing: 1px;
  border: none;
  position: relative;
  background-color: transparent;
  transition: 0.2s cubic-bezier(0.19, 1, 0.22, 1);
  opacity: 0.6;
}

.btn::after {
  content: "";
  border-bottom: 5px double #fff200;
  width: 0;
  height: 100%;
  position: absolute;
  margin-top: -5px;
  top: 0;
  left: 5px;
  visibility: hidden;
  opacity: 1;
  transition: 0.2s linear;
}

.btn .icon {
  transform: translateX(0%);
  transition: 0.2s linear;
  animation: attention 1.2s linear infinite;
}

.btn:hover::after {
  visibility: visible;
  opacity: 0.7;
  width: 90%;
}

.btn:hover {
  letter-spacing: 2px;
  opacity: 1;
}

.btn:hover > .icon {
  transform: translateX(30%);
  animation: none;
}

@keyframes attention {
  0% {
    transform: translateX(0%);
  }

  50% {
    transform: translateX(30%);
  }
}
</style>